package com.gouwudai.gobbs.service.impl;

import java.util.Date;
import java.util.List;

import com.gouwudai.gobbs.dao.ITopicIlikeDAO;
import com.gouwudai.gobbs.pojo.TbbsTopicIlike;
import com.gouwudai.gobbs.service.ITopicIlikeService;
import com.litt.core.exception.DBException;

public class TopicIlikeServiceImpl implements ITopicIlikeService
{
	ITopicIlikeDAO topicIlikeDAO;
	
	/**
	 * 新增或更新订阅
	 * @param topicId
	 * @param userId
	 * @return
	 */
	public void doBookTopic(int topicId,int userId)
	{	
		
			TbbsTopicIlike tbbsTopicIlike = topicIlikeDAO.load(topicId,userId);
			if(tbbsTopicIlike==null)	//新增
			{	
				tbbsTopicIlike = new TbbsTopicIlike();
				tbbsTopicIlike.setTopicId(topicId);
				tbbsTopicIlike.setUserId(userId);
				tbbsTopicIlike.setAddDatetime(new Date());
				tbbsTopicIlike.setLastDatetime(new Date());
				topicIlikeDAO.save(tbbsTopicIlike);
			}
			else	//更新
			{
				tbbsTopicIlike.setLastDatetime(new Date());
				topicIlikeDAO.update(tbbsTopicIlike);
			}	
	}	
	
	
	public void save(TbbsTopicIlike tbbsTopicIlike)
	{	
		topicIlikeDAO.save(tbbsTopicIlike);
	}

	public TbbsTopicIlike load(Integer id)
	{
		return (TbbsTopicIlike)topicIlikeDAO.load(id);
	}

	public void update(TbbsTopicIlike tbbsTopicIlike)
	{
			topicIlikeDAO.update(tbbsTopicIlike);
	}

	public void delete(String ids)
	{
			topicIlikeDAO.delete(ids);
	}
	
    /**
     * 查询我订阅的话题
     * @param userId
     * @param pageIndex
     * @param pageSize
     * @return
     * @throws DBException
     */
    public List listByUserId(int userId,int pageIndex,int pageSize)
    {
    	return topicIlikeDAO.listByUserId(userId, pageIndex, pageSize);
    }

    /**
     * 分页统计
     * @param userId
     * @param pageIndex
     * @param pageSize
     * @return
     * @throws DBException
     */
    public int listCountByUserId(int userId)
    {
    	return topicIlikeDAO.listCountByUserId(userId);
    }


	public void setTopicIlikeDAO(ITopicIlikeDAO topicIlikeDAO) {
		this.topicIlikeDAO = topicIlikeDAO;
	}
	
}